import axios from 'axios';
//import router from '../router';

const baseURL = 'http://localhost:5173';

const instance = axios.create({
    baseURL,
    timeout: 10000,
});

//请求拦截器
instance.interceptors.request.use(
    (config) => {
        // const userStore = useUserStores();
        // if (userStore.token) {
        //     config.headers.Authorization = userStore.token;
        // }
        return config;
    },
    (err) => Promise.reject(err),
)

instance.interceptors.response.use(
    (res) => {
        switch (res.data.code) {
            case 0:
                return res;
        }
        return Promise.reject(res.data);
    },
    (err) => {
        //401 权限不足
        // if (err.response?.status === 401) {
        //     router.push('/login');
        // }

        //默认
        return Promise.reject(err)
    },
)

export default instance;
export { baseURL };
